/**
 * 全站路由配置
 *
 * 建议:
 * 1. 代码中路由统一使用name属性跳转(不使用path属性)
 */
import Vue from 'vue'
import Router from 'vue-router'
import http from '@/utils/httpRequest'
import {
  isURL
} from '@/utils/validate'
import {
  clearLoginInfo
} from '@/utils'

Vue.use(Router)

// 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
const _import = require('./import-' + process.env.NODE_ENV)

// 全局路由(无需嵌套上左右整体布局)
const globalRoutes = [{
  path: '/404',
  component: _import('common/404'),
  name: '404',
  meta: {
    title: '404未找到'
  }
},
  {
    path: '/login',
    //component: _import('common/login'),
    component: _import('login'),
    name: 'login',
    meta: {
      title: '登录'
    }
  }
]

//菜单
const menuList = [
  {
    "menuId": 31,
    "parentId": 0,
    "parentName": null,
    "name": "首页",
    "url": "home",
    "perms": "",
    "type": 0,
    "icon": "zhedie",
    "orderNum": 0,
    "isHide": null,
    "open": null,
    "list": []
  }, 
  {
    "menuId": 59,
    "parentId": 0,
    "parentName": null,
    "name": "基础配置",
    "url": null,
    "perms": "",
    "type": 0,
    "icon": "editor",
    "orderNum": 2,
    "isHide": null,
    "open": null,
    "list": [
    {
      "menuId": 130,
      "parentId": 59,
      "parentName": null,
      "name": "因子管理",
      "url": "drools/baseConfig/divisor/list",
      "perms": "",
      "type": 1,
      "icon": "tixing",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list":[
        {
          "menuId": 133,
          "parentId": 130,
          "parentName": null,
          "name": "因子配置",
          "url": "drools/baseConfig/divisor/list",
          "perms": "",
          "type": 1,
          "icon": "tixing",
          "orderNum": 0,
          "isHide": null,
          "open": null,
          "list": null
        }, 
        // {
        //   "menuId": 135,
        //   "parentId": 130,
        //   "parentName": null,
        //   "name": "公式因子",
        //   "url": "drools/baseConfig/formula/list",
        //   "perms": "formula/list",
        //   "type": 1,
        //   "icon": "tubiao",
        //   "orderNum": 1,
        //   "isHide": null,
        //   "open": null,
        //   "list": null
        // }
      ]
    },
    {
      "menuId": 32,
      "parentId": 59,
      "parentName": null,
      "name": "模型管理",
      "url": "drools/baseConfig/entity/list",
      "perms": "entity:list",
      "type": 1,
      "icon": "zonghe",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    }, 
    // {
    //   "menuId": 40,
    //   "parentId": 59,
    //   "parentName": null,
    //   "name": "规则属性",
    //   "url": "drools/baseConfig/property/list",
    //   "perms": "property:list",
    //   "type": 1,
    //   "icon": "editor",
    //   "orderNum": 0,
    //   "isHide": null,
    //   "open": null,
    //   "list": null
    // }, 
     {
      "menuId": 81,
      "parentId": 59,
      "parentName": null,
      "name": "规则条件",
      "url": "drools/baseConfig/conditionDivisor/list",
      "perms": "conditionDivisor:list",
      "type": 1,
      "icon": "tixing",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    }, {
      "menuId": 82,
      "parentId": 59,
      "parentName": null,
      "name": "规则动作",
      "url": "drools/baseConfig/actionDivisor/list",
      "perms": "actionDivisor/list",
      "type": 1,
      "icon": "role",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    }, {
      "menuId": 83,
      "parentId": 59,
      "parentName": null,
      "name": "环境配置",
      "url": "drools/baseConfig/environment/list",
      "perms": "environment:list",
      "type": 1,
      "icon": "sql",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    },
    // {
    //   "menuId": 77,
    //   "parentId": 59,
    //   "parentName": null,
    //   "name": "渠道管理",
    //   "url": "drools/channel/list",
    //   "perms": "channel:list",
    //   "type": 1,
    //   "icon": "role",
    //   "orderNum": 0,
    //   "isHide": null,
    //   "open": null,
    //   "list": null
    // },
  ]
  },
  {
    "menuId": 57,
    "parentId": 0,
    "parentName": null,
    "name": "规则定义",
    "url": null,
    "perms": "",
    "type": 0,
    "icon": "bianji",
    "orderNum": 3,
    "isHide": null,
    "open": null,
    "list": [{
      "menuId": 131,
      "parentId": 100,
      "parentName": null,
      "name": "任务管理",
      "url": "",
      "perms": "",
      "type": 0,
      "icon": "zhedie",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": [{
        "menuId": 132,
        "parentId": 100,
        "parentName": null,
        "name": "任务管理",
        "url": "drools/version/tasklist",
        "perms": "",
        "type": 1,
        "icon": "zhedie",
        "orderNum": 0,
        "isHide": null,
        "open": null,
        "list": null
      }, {
        "menuId": 136,
        "parentId": 100,
        "parentName": null,
        "name": "任务审核",
        "url": "drools/version/taskauditlist",
        "perms": "",
        "type": 1,
        "icon": "shenhe",
        "orderNum": 1,
        "isHide": null,
        "open": null,
        "list": null
      }]
    },{
      "menuId": 90,
      "parentId": 57,
      "parentName": null,
      "name": "规则组",
      "url": null,
      "perms": "",
      "type": 0,
      "icon": "editor",
      "orderNum": 1,
      "isHide": null,
      "open": null,
      "list": [{
        "menuId": 35,
        "parentId": 57,
        "parentName": null,
        "name": "规则组",
        "url": "drools/ruleConfig/group/list",
        "perms": "scene:list",
        "type": 1,
        "icon": "mudedi",
        "orderNum": 2,
        "isHide": null,
        "open": null,
        "list": null
      }]
    },{
      "menuId": 84,
      "parentId": 57,
      "parentName": null,
      "name": "流程管理",
      "url": "drools/ruleConfig/flow/list",
      "perms": "flow:list",
      "type": 1,
      "icon": "pinglun",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    }, {
      "menuId": 85,
      "parentId": 57,
      "parentName": null,
      "name": "场景管理",
      "url": "drools/ruleConfig/scene/list",
      "perms": "scene:list",
      "type": 1,
      "icon": "oss",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    },
    //  {
    //   "menuId": 137,
    //   "parentId": 57,
    //   "parentName": null,
    //   "name": "责任规则定义",
    //   "url": "",
    //   "perms": "",
    //   "type": 0,
    //   "icon": "menu",
    //   "orderNum": 2,
    //   "isHide": null,
    //   "open": null,
    //   "list": [
    //     {
    //       "menuId": 138,
    //       "parentId": 137,
    //       "parentName": null,
    //       "name": "险种规则定义",
    //       "url": "drools/ruleConfig/zerenrules/insurance-rules",
    //       "perms": "",
    //       "type": 1,
    //       "icon": "",
    //       "orderNum": 3,
    //       "isHide": null,
    //       "open": null,
    //       "list": null
    //     },
    //     {
    //       "menuId": 139,
    //       "parentId": 137,
    //       "parentName": null,
    //       "name": "险种规则导航菜单",
    //       "url": "drools/ruleConfig/zerenrules/menus-rules",
    //       "perms": "",
    //       "type": 1,
    //       "icon": "",
    //       "orderNum": 3,
    //       "isHide": null,
    //       "open": null,
    //       "list": null
    //     },
    //     {
    //       "menuId": 140,
    //       "parentId": 137,
    //       "parentName": null,
    //       "name": "险种规则导航类型",
    //       "url": "drools/ruleConfig/zerenrules/type-rules",
    //       "perms": "",
    //       "type": 1,
    //       "icon": "",
    //       "orderNum": 3,
    //       "isHide": null,
    //       "open": null,
    //       "list": null
    //     },
    //   ]
    // }
  ]}, 
  {
    "menuId": 86,
    "parentId": 0,
    "parentName": null,
    "name": "场景案例",
    "url": "",
    "perms": "",
    "type": 0,
    "icon": "config",
    "orderNum": 6,
    "isHide": null,
    "open": null,
    "list": [{
      "menuId": 87,
      "parentId": 86,
      "parentName": null,
      "name": "场景案例模板",
      "url": "drools/testCase/interfaceTemplate/list",
      "perms": "interfaceTemplate:list",
      "type": 1,
      "icon": "oss",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    },

      {
      "menuId": 88,
      "parentId": 86,
      "parentName": null,
      "name": "场景案例",
      "url": "drools/testCase/interfaceCase/list",
      "perms": "interfaceCase:list",
      "type": 1,
      "icon": "menu",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    },
    ]
  }, 
  // {
  //   "menuId": 100,
  //   "parentId": 0,
  //   "parentName": null,
  //   "name": "版本管理",
  //   "url": "",
  //   "perms": "",
  //   "type": 0,
  //   "icon": "oss",
  //   "orderNum": 5,
  //   "isHide": null,
  //   "open": null,
  //   "list": [{
  //     "menuId": 101,
  //     "parentId": 100,
  //     "parentName": null,
  //     "name": "规则组版本",
  //     "url": "drools/version/rulegrouplist",
  //     "perms": "",
  //     "type": 1,
  //     "icon": "zhedie",
  //     "orderNum": 0,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 102,
  //     "parentId": 100,
  //     "parentName": null,
  //     "name": "流程版本",
  //     "url": "drools/version/flowlist",
  //     "perms": "",
  //     "type": 1,
  //     "icon": "zhedie",
  //     "orderNum": 0,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 109,
  //     "parentId": 100,
  //     "parentName": null,
  //     "name": "流程版本比较",
  //     "url": "drools/version/flowcompare",
  //     "perms": "",
  //     "type": 1,
  //     "icon": "zhedie",
  //     "orderNum": 0,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 110,
  //     "parentId": 100,
  //     "parentName": null,
  //     "name": "规则组版本比较",
  //     "url": "drools/version/rulegroupcompare",
  //     "perms": "",
  //     "type": 1,
  //     "icon": "zhedie",
  //     "orderNum": 0,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }]
  // }, 
  // {
  //   "menuId": 1,
  //   "parentId": 0,
  //   "parentName": null,
  //   "name": "系统管理",
  //   "url": "",
  //   "perms": null,
  //   "type": 0,
  //   "icon": "system",
  //   "orderNum": 1,
  //   "isHide": null,
  //   "open": null,
  //   "list": [{
  //     "menuId": 2,
  //     "parentId": 1,
  //     "parentName": null,
  //     "name": "管理员列表",
  //     "url": "sys/user",
  //     "perms": null,
  //     "type": 1,
  //     "icon": "admin",
  //     "orderNum": 1,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 3,
  //     "parentId": 1,
  //     "parentName": null,
  //     "name": "角色管理",
  //     "url": "sys/role",
  //     "perms": null,
  //     "type": 1,
  //     "icon": "role",
  //     "orderNum": 2,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 4,
  //     "parentId": 1,
  //     "parentName": null,
  //     "name": "菜单管理",
  //     "url": "sys/menu",
  //     "perms": null,
  //     "type": 1,
  //     "icon": "menu",
  //     "orderNum": 3,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 27,
  //     "parentId": 1,
  //     "parentName": null,
  //     "name": "参数管理",
  //     "url": "sys/config",
  //     "perms": "sys:config:list,sys:config:info,sys:config:save,sys:config:update,sys:config:delete",
  //     "type": 1,
  //     "icon": "config",
  //     "orderNum": 6,
  //     "isHide": "1",
  //     "open": null,
  //     "list": null
  //   }, {
  //     "menuId": 29,
  //     "parentId": 1,
  //     "parentName": null,
  //     "name": "系统日志",
  //     "url": "sys/log",
  //     "perms": "sys:log:list",
  //     "type": 1,
  //     "icon": "log",
  //     "orderNum": 7,
  //     "isHide": null,
  //     "open": null,
  //     "list": null
  //   }]
  // },
  {
    "menuId": 111,
    "parentId": 0,
    "parentName": null,
    "name": "运维监控",
    "url": "",
    "perms": "",
    "type": 0,
    "icon": "mudedi",
    "orderNum": 7,
    "isHide": null,
    "open": null,
    "list": [{
      "menuId": 112,
      "parentId": 111,
      "parentName": null,
      "name": "规则运行日志",
      "url": "drools/log/list",
      "perms": "",
      "type": 1,
      "icon": "zhedie",
      "orderNum": 0,
      "isHide": null,
      "open": null,
      "list": null
    }]
  }
]
//菜单按钮权限
const permissions = ["entity:view", "sys:menu:update", "sys:menu:delete", "sys:config:info", "formula/list", "sys:menu:list", "sys:config:save", "entity:sync", "sys:config:update", "scene:edit", "entity:list", "property:list", "sys:user:delete", "sys:config:list", "sys:user:update", "sys:role:list", "sys:menu:info", "sys:menu:select", "interfaceTemplate:list", "sys:role:select", "scene:delete", "flow:list", "channel:add", "sys:user:list", "sys:menu:save", "sys:role:save", "channel:list", "sys:role:info", "scene:view", "sys:role:update", "sys:user:info", "sys:config:delete", "channel:delete", "scene:add", "scene:publish", "sys:role:delete", "channel:edit", "scene:test", "sys:user:save", "scene:list", "conditionDivisor:list", "environment:list", "interfaceCase:list", "actionDivisor/list", "sys:log:list"]
// 主入口路由(需嵌套上左右整体布局)
const mainRoutes = {
  path: '/',
  component: _import('main'),
  name: 'main',
  redirect: {
    name: 'home'
  },
  meta: {
    title: '主入口整体布局'
  },
  children: [
    // 通过meta对象设置路由展示方式
    // 1. isTab: 是否通过tab展示内容, true: 是, false: 否
    // 2. iframeUrl: 是否通过iframe嵌套展示内容, '以http[s]://开头': 是, '': 否
    // 提示: 如需要通过iframe嵌套展示内容, 但不通过tab打开, 请自行创建组件使用iframe处理!
    {
      path: '/home',
      component: _import('common/home'),
      name: 'home',
      meta: {
        title: '首页'
      }
    },
    {
      path: '/theme',
      component: _import('common/theme'),
      name: 'theme',
      meta: {
        title: '主题'
      }
    },
    {
      path: '/demo-echarts',
      component: _import('demo/echarts'),
      name: 'demo-echarts',
      meta: {
        title: 'demo-echarts',
        isTab: true
      }
    },
    {
      path: '/demo-ueditor',
      component: _import('demo/ueditor'),
      name: 'demo-ueditor',
      meta: {
        title: 'demo-ueditor',
        isTab: true
      }
    },
    {
      path: '/demo-X6',
      component: _import('demo/X6/X6'),
      name: 'demo-X6',
      meta: {
        title: 'demo-X6',
        isTab: true
      }
    },
    {
      path: '/demo',
      component: _import('demo/X6/demo'),
      name: 'demo',
      meta: {
        title: 'demo',
        isTab: true
      }
    },

    {
      path: '/drools-ruleConfig/group/add-or-update/:id/:type',
      component: _import('modules/drools/ruleConfig/group/add-or-update'),
      name: 'editGroup',
      meta: {
        title: '规则组',
        isTab: true,
        parentId: 35
      }
    },
    {
      path: '/drools-ruleConfig/group/add-or-update',
      component: _import('modules/drools/ruleConfig/group/add-or-update'),
      name: 'addGroup',
      meta: {
        title: '规则组',
        isTab: true,
        parentId: 35
      }
    },
    {
      path: '/drools-ruleConfig/group/view/:id/:type',
      component: _import('modules/drools/ruleConfig/group/view'),
      name: 'viewGroup',
      meta: {
        title: '规则组',
        isTab: true,
        parentId: 35,
        isDisabled:true
      }
    },
    {
      path: '/drools-version/conflict-resolve/:id',
      component: _import('modules/drools/version/conflict-resolve'),
      name: 'conflictresolve',
      meta: {
        title: '解决冲突',
        isTab: true,
        parentId: 131
      }
    },

    {
      path: '/drools-ruleConfig/decision/add-or-update/:id',
      component: _import('modules/drools/ruleConfig/decision/add-or-update'),
      name: 'editDecision',
      meta: {
        title: '决策表',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/decision/add-or-update',
      component: _import('modules/drools/ruleConfig/decision/add-or-update'),
      name: 'addDecision',
      meta: {
        title: '决策表',
        isTab: true,
        parentId: 57
      }
    },

    {
      path: '/drools-ruleConfig/branch/add-decision/:id',
      component: _import('modules/drools/ruleConfig/branch/add-decision'),
      name: 'editBranchDecision',
      meta: {
        title: '分支决策表',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/branch/add-or-update/:id',
      component: _import('modules/drools/ruleConfig/branch/add-or-update'),
      name: 'editBranch',
      meta: {
        title: '分支规则组',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/branch/add-or-update',
      component: _import('modules/drools/ruleConfig/branch/add-or-update'),
      name: 'addBranch',
      meta: {
        title: '分支规则组',
        isTab: true,
        parentId: 57
      }
    },

    {
      path: '/drools-ruleConfig/branch/add-rule/:branchCode/:groupIdentify/:groupId',
      component: _import('modules/drools/ruleConfig/branch/add-rule'),
      name: 'editbranch',
      meta: {
        title: '分支规则',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/branch/edit-rule/:id/:groupId',
      component: _import('modules/drools/ruleConfig/branch/edit-rule'),
      name: 'branchRule',
      meta: {
        title: '分支规则',
        isTab: true,
        parentId: 57
      }
    },

    {
      path: '/drools-ruleConfig/rule/add-or-update/:id/:type',
      component: _import('modules/drools/ruleConfig/rule/add-or-update'),
      name: 'editRule',
      meta: {
        title: '规则',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/rule/add-or-update',
      component: _import('modules/drools/ruleConfig/rule/add-or-update'),
      name: 'addRule',
      meta: {
        title: '规则',
        isTab: true,
        parentId: 57
      }
    },

    {
      path: '/drools-ruleConfig/flow/edit-flow/:id/:rowTaskNo/:taskNo/:flowIdentify',
      component: _import('modules/drools/ruleConfig/flow/edit-flow'),
      name: 'editFlow',
      meta: {
        title: '流程管理',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/flow/edit-flow/:taskNo',
      component: _import('modules/drools/ruleConfig/flow/edit-flow'),
      name: 'addFlow',
      meta: {
        title: '流程管理',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/flow/view-flow/:id/:rowTaskNo/:flowIdentify',
      component: _import('modules/drools/ruleConfig/flow/view-flow'),
      name: 'view',
      meta: {
        title: '流程管理',
        isTab: true,
        parentId: 57
      }
    },

    {
      path: '/drools-ruleConfig/scene/edit-flow/:id',
      component: _import('modules/drools/ruleConfig/scene/edit-flow'),
      name: 'editScene',
      meta: {
        title: '场景管理',
        isTab: true,
        parentId: 57
      }
    },
    {
      path: '/drools-ruleConfig/scene/edit-flow',
      component: _import('modules/drools/ruleConfig/scene/edit-flow'),
      name: 'addScene',
      meta: {
        title: '场景管理',
        isTab: true,
        parentId: 57
      }
    },

    {
      path: '/drools-baseConfig/entity/add-or-update/:id',
      component: _import('modules/drools/baseConfig/entity/add-or-update'),
      name: 'editEntity',
      meta: {
        title: '模型管理',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-baseConfig/entity/view-entity/:id',
      component: _import('modules/drools/baseConfig/entity/view-entity'),
      name: 'viewEntity',
      meta: {
        title: '模型管理',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-baseConfig/entity/add-or-update',
      component: _import('modules/drools/baseConfig/entity/add-or-update'),
      name: 'addEntity',
      meta: {
        title: '模型管理',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-baseConfig/entity/view-data/:id',
      component: _import('modules/drools/baseConfig/entity/view-data'),
      name: 'viewData',
      meta: {
        title: '模型管理',
        isTab: true,
        parentId: 59
      }
    },

    {
      path: '/drools-baseConfig/conditionDivisor/add-or-update/:id',
      component: _import('modules/drools/baseConfig/conditionDivisor/add-or-update'),
      name: 'editConditionDivisor',
      meta: {
        title: '规则条件',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-baseConfig/conditionDivisor/add-or-update',
      component: _import('modules/drools/baseConfig/conditionDivisor/add-or-update'),
      name: 'addConditionDivisor',
      meta: {
        title: '规则条件',
        isTab: true,
        parentId: 59
      }
    },

    {
      path: '/drools-baseConfig/actionDivisor/add-or-update/:id',
      component: _import('modules/drools/baseConfig/actionDivisor/add-or-update'),
      name: 'editActionDivisor',
      meta: {
        title: '规则动作',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-baseConfig/actionDivisor/add-or-update',
      component: _import('modules/drools/baseConfig/actionDivisor/add-or-update'),
      name: 'addActionDivisor',
      meta: {
        title: '规则动作',
        isTab: true,
        parentId: 59
      }
    },

    {
      path: '/drools-testCase/interfaceTemplate/add-or-update/:id',
      component: _import('modules/drools/testCase/interfaceTemplate/add-or-update'),
      name: 'editInterfaceTemplate',
      meta: {
        title: '接口模版',
        isTab: true,
        parentId: 86
      }
    },
    {
      path: '/drools-testCase/interfaceTemplate/add-or-update',
      component: _import('modules/drools/testCase/interfaceTemplate/add-or-update'),
      name: 'addInterfaceTemplate',
      meta: {
        title: '接口模版',
        isTab: true,
        parentId: 86
      }
    },

    {
      path: '/drools-testCase/interfaceCase/add-or-update/:id',
      component: _import('modules/drools/testCase/interfaceCase/add-or-update'),
      name: 'editInterfaceCase',
      meta: {
        title: '接口案例',
        isTab: true,
        parentId: 86
      }
    },
    {
      path: '/drools-testCase/interfaceCase/add-or-update',
      component: _import('modules/drools/testCase/interfaceCase/add-or-update'),
      name: 'addInterfaceCase',
      meta: {
        title: '接口案例',
        isTab: true,
        parentId: 86
      }
    },

    {
      path: '/drools-testCase/groupCase/add-or-update/:id',
      component: _import('modules/drools/testCase/groupCase/add-or-update'),
      name: 'editGroupCase',
      meta: {
        title: '规则案例',
        isTab: true,
        parentId: 86
      }
    },
    {
      path: '/drools-testCase/groupCase/add-or-update',
      component: _import('modules/drools/testCase/groupCase/add-or-update'),
      name: 'addGroupCase',
      meta: {
        title: '规则案例',
        isTab: true,
        parentId: 86
      }
    },

    {
      path: '/drools-release/view-group/:id',
      component: _import('modules/drools/release/view-group'),
      name: 'viewgroup',
      meta: {
        title: '规则组',
        isTab: true,
        parentId: 100
      }
    },

    {
      path: '/drools-version/view-group/:groupIdentify/:groupVersion/:type',
      component: _import('modules/drools/version/view-group'),
      name: 'viewgrouptype',
      meta: {
        title: '规则组',
        isTab: true,
        parentId: 100
      }
    },
    {
      path: '/drools-version/view-flow/:flowIdentify/:flowVersion/:type',
      component: _import('modules/drools/version/view-flow'),
      name: 'view-flow-type',
      meta: {
        title: '流程管理',
        isTab: true,
        parentId: 100
      }
    },
    {
      path: '/drools-version/view-task/:taskNo',
      component: _import('modules/drools/version/view-task'),
      name: 'view-task',
      meta: {
        title: '任务详情',
        isTab: true,
        parentId: 100
      }
    },
    // 审核
    {
      path: '/drools-version/taskauditview/:taskNo',
      component: _import('modules/drools/version/taskauditview'),
      name: 'taskauditview',
      meta: {
        title: '任务审核详情',
        isTab: true,
        parentId: 100
      }
    },
    {
      path: '/drools-baseConfig/formula/add-or-update/:id',
      component: _import('modules/drools/baseConfig/formula/add-or-update'),
      name: 'editformula',
      meta: {
        title: '编辑公式因子',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-baseConfig/formula/add-or-update',
      component: _import('modules/drools/baseConfig/formula/add-or-update'),
      name: 'addformula',
      meta: {
        title: '新增公式因子',
        isTab: true,
        parentId: 59
      }
    },
    {
      path: '/drools-ruleConfig/zerenrules/edit/:id',
      component: _import('modules/drools/ruleConfig/zerenrules/edit'),
      name: 'editzerenrules',
      meta: {
        title: '险种规则定义',
        isTab: true,
        isDisabled: true,
        parentId: 137
      }
    },
    {
      path: '/drools-ruleConfig/zerenrules/edit',
      component: _import('modules/drools/ruleConfig/zerenrules/edit'),
      name: 'addzerenrules',
      meta: {
        title: '险种规则定义',
        isDisabled: true,
        isTab: true,
        parentId: 137
      }
    },
    {
      path: '/drools-testCase/interfaceCase/add-or-update/:id',
      component: _import('modules/drools/testCase/interfaceCase/add-or-update'),
      name: 'editscene',
      meta: {
        title: '场景案例-新增',
        isTab: true,
        parentId: 88
      }
    },
    {
      path: '/drools-testCase/interfaceCase/test',
      component: _import('modules/drools/testCase/interfaceCase/test'),
      name: 'addscene',
      meta: {
        title: '场景案例-测试',
        isTab: true,
        parentId: 88
      }
    },
  ],
  beforeEnter(to, from, next) {
    let token = Vue.cookie.get('token')
    if (!token || !/\S/.test(token)) {
      clearLoginInfo()
      next({
        name: 'login'
      })
    }
    next()
  }
}

const router = new Router({
  mode: 'hash',
  scrollBehavior: () => ({
    y: 0
  }),
  isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
  routes: globalRoutes.concat(mainRoutes)
})

router.beforeEach((to, from, next) => {
  // 添加动态(菜单)路由
  // 1. 已经添加 or 全局路由, 直接访问
  // 2. 获取菜单列表, 添加并保存本地存储

  // console.log("to",to);
  if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') {
    next()
  } else {
    for (var i = 0; i < menuList.length; i++) {
      if (menuList[i].list && menuList[i].list.length >= 1) {
        let menulist1 = getMenu(menuList[i].menuId, menuList[i].list)
        menuList[i].list = menulist1
      }
    }
    fnAddDynamicMenuRoutes(menuList)
    router.options.isAddDynamicMenuRoutes = true
    sessionStorage.setItem('menuList', JSON.stringify(menuList || '[]'))
    sessionStorage.setItem('permissions', JSON.stringify(permissions || '[]'))
    next({
      ...to,
      replace: true
    })
  }

  // if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') {
  //   next()
  // } else {
  //   http({
  //     url: http.adornUrl('/sys/menu/nav'),
  //     method: 'get',
  //     params: http.adornParams()
  //   }).then(({
  //              data
  //            }) => {
  //     if (data && data.code === 0) {
  //
  //       for (var i = 0; i < data.menuList.length; i++) {
  //         if (data.menuList[i].list && data.menuList[i].list.length >= 1) {
  //           let menulist = getMenu(data.menuList[i].menuId, data.menuList[i].list)
  //           data.menuList[i].list = menulist
  //         }
  //       }
  //       // console.log(data.menuList)
  //
  //       fnAddDynamicMenuRoutes(data.menuList)
  //       router.options.isAddDynamicMenuRoutes = true
  //       sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]'))
  //       sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]'))
  //       next({
  //         ...to,
  //         replace: true
  //       })
  //     } else {
  //       sessionStorage.setItem('menuList', '[]')
  //       sessionStorage.setItem('permissions', '[]')
  //       next()
  //     }
  //   }).catch((e) => {
  //     // console.log(`%c${e} 请求菜单列表和权限失败，跳转至登录页！！`, 'color:blue')
  //     router.push({
  //       name: 'login'
  //     })
  //   })
  // }
})

/**
 * 判断当前路由类型, global: 全局路由, main: 主入口路由
 * @param {*} route 当前路由
 */
function fnCurrentRouteType(route, globalRoutes = []) {
  var temp = []
  for (var i = 0; i < globalRoutes.length; i++) {
    if (route.path === globalRoutes[i].path) {
      return 'global'
    } else if (globalRoutes[i].children && globalRoutes[i].children.length >= 1) {
      temp = temp.concat(globalRoutes[i].children)
    }
  }
  return temp.length >= 1 ? fnCurrentRouteType(route, temp) : 'main'
}

/**
 *
 * @param menu 当前菜单
 * @param menuList 所有菜单
 * @param menus 菜单目录
 * @returns {null|*}
 */
function getMenu(parentId, menuList) {
  for (var i = 0; i < menuList.length; i++) {
    if (menuList[i].list && menuList[i].list.length >= 1) {
      getMenu(parentId, menuList[i].list)
    }
    menuList[i].parentId = parentId
  }
  return menuList;
}

/**
 * 添加动态(菜单)路由
 * @param {*} menuList 菜单列表
 * @param {*} routes 递归创建的动态(菜单)路由
 */
function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
  var temp = []

  for (var i = 0; i < menuList.length; i++) {
    if (menuList[i].list && menuList[i].list.length >= 1) {
      temp = temp.concat(menuList[i].list)
    } else if (menuList[i].url && /\S/.test(menuList[i].url)) {
      menuList[i].url = menuList[i].url.replace(/^\//, '')
      var route = {
        path: menuList[i].url.replace('/', '-'),
        component: null,
        name: menuList[i].url.replace('/', '-'),
        meta: {
          menuId: menuList[i].menuId,
          title: menuList[i].name,
          isDynamic: true,
          parentId: menuList[i].parentId,
          isTab: true,
          iframeUrl: ''
        }
      }
      // url以http[s]://开头, 通过iframe展示
      if (isURL(menuList[i].url)) {
        route['path'] = `i-${menuList[i].menuId}`
        route['name'] = `i-${menuList[i].menuId}`
        route['meta']['iframeUrl'] = menuList[i].url
      } else {
        try {
          route['component'] = _import(`modules/${menuList[i].url}`) || null
        } catch (e) {
        }
      }
      routes.push(route)
    }
  }
  
  if (temp.length >= 1) {
    fnAddDynamicMenuRoutes(temp, routes)
  } else {
    mainRoutes.name = 'main-dynamic'
    mainRoutes.children = routes
    router.addRoutes([
      mainRoutes,
      {
        path: '*',
        redirect: {
          name: '404'
        }
      }
    ])
    sessionStorage.setItem('dynamicMenuRoutes', JSON.stringify(mainRoutes.children || '[]'))
    // console.log('\n')
    // console.log('%c!<-------------------- 动态(菜单)路由 s -------------------->', 'color:blue')
    // console.log(mainRoutes.children)
    // console.log('%c!<-------------------- 动态(菜单)路由 e -------------------->', 'color:blue')
  }
  // console.log(routes);
}

export default router
